<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用jQuery封装后的Ajax</title>
    <script src="jquery-3.6.1.js"></script>
</head>
<body>
<table>
    <tr>
        <td>用户名：</td> <td><input type="text" name="username" class="username"></td>
    </tr>
    <tr>
        <td>密码：</td> <td><input type="password" name="password" class="password"></td>
    </tr>
</table>
<button id="main">登陆验证</button>
<h2 style="color: #2b542c">已存在</h2>
<p class="data"></p>
<script>
    $('#main').click(() => {
        $.ajax({
            url:'http://localhost/ajaxServer',
            data:{
                username:$('.username').val(),
                password:$('.password').val()
            },
            success(login){
                if(login === "true"){
                    $('.data').html(login)
                }else {
                    $('.data').html(login)
                }
            }
        })
    })
</script>
</body>
</html>